/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.purpose.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.koron.purpose.bean.WorkListTypeBean;
import com.koron.purpose.domain.WorkListType;

public interface WorkListTypeMapper {
	
	@Insert("insert into work_list_type(id,add_user,add_time,update_user,update_time,add_user_name,update_user_name,corp_code,corp_name,work_type_id,work_type_label,work_content,work_explain,cycle_id,cycle_label,note,router,is_external) "
			+ "values(#{id},#{addUser},#{addTime},#{updateUser},#{updateTime},#{addUserName},#{updateUserName},#{corpCode},#{corpName},#{workTypeId},#{workTypeLabel},#{workContent},#{workExplain},#{cycleId},#{cycleLabel},#{note},#{router},#{isExternal})")
	int insert(WorkListType bean);
	
	@Update("update work_list_type set state=0 where id=#{id}")
	int delete(@Param("id") String id); 
	
	@Update("update work_list_type set update_time=#{updateTime},update_user=#{updateUser},update_user_name=#{updateUserName},"
			+"corp_code=#{corpCode},corp_name=#{corpName},"
			+ "work_type_id=#{workTypeId},work_type_label=#{workTypeLabel},work_content=#{workContent},work_explain=#{workExplain},"
			+ "cycle_id=#{cycleId},cycle_label=#{cycleLabel},note=#{note},router=#{router},is_external=#{isExternal} where id=#{id}")
	int update(WorkListType bean);
	
	@Select("<script>"
			+ "select count(*) from work_list_type where 1=1 "
			+ "<if test='corpCode!=null and !corpCode.isEmpty()'> and corp_code =#{corpCode}</if>"
			+ "<if test='workTypeId!=null and !workTypeId.isEmpty()'> and work_type_id =#{workTypeId}</if>"
			+ "<if test='workContent!=null'> and work_content like CONCAT(CONCAT('%',#{workContent}),'%') </if>"
			+ "<if test='cycleId!=null and !cycleId.isEmpty()'> and cycle_id =#{cycleId}</if>"
			+ "<if test='state!=null'> and state =#{state}</if>"
			+ "</script>")
	int count(WorkListTypeBean bean);
	
	@Select("<script>"
			+ "select * from work_list_type where 1=1 "
			+ "<if test='corpCode!=null and !corpCode.isEmpty()'> and corp_code =#{corpCode}</if>"
			+ "<if test='workTypeId!=null and !workTypeId.isEmpty()'> and work_type_id =#{workTypeId}</if>"
			+ "<if test='workContent!=null'> and work_content like CONCAT(CONCAT('%',#{workContent}),'%') </if>"
			+ "<if test='cycleId!=null and !cycleId.isEmpty()'> and cycle_id =#{cycleId}</if>"
			+ "<if test='state!=null'> and state =#{state}</if>"
			+ "order by work_type_id, update_time desc"
			+ "<if test='start!=null and end!=null'> limit #{start},#{end}</if>"
			+ "</script>")
	List<WorkListType> query(WorkListTypeBean bean);
	
	@Select("select * from work_list_type where id=#{id}")
	WorkListType queryById(@Param("id")String id);
	
}
